<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('K号查询列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <p>K号：</p>
                                <input type="text" name="no"/>
                            </li>
                            <li>
                                <p>KKID：</p>
                                <input type="text" name="kkid"/>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('user:kknumber:edit')}]];
        var removeFlag = [[${@permission.hasPermi('user:kknumber:remove')}]];
        var appIdDatas = [[${@dict.getType('storage_app_type')}]];
        var prefix = ctx + "user/kknumber";
        var privilegePrefix = ctx + "user/userprivilege";
        var sendPrivilegePrefix = ctx + "user/userprivilege/add";

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "K号查询",
                columns: [{
                    checkbox: true
                },
                {
                    field : 'id', 
                    title : 'ID',
                    visible: false
                },
                {
                    field : 'no', 
                    title : 'K号'
                },
                {
                    field : 'appId', 
                    title : '应用ID',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(appIdDatas, value);
                    }
                },
                {
                    field : 'kkid', 
                    title : 'KKID'
                },
                {
                    field : 'nickname',
                    title : '昵称'
                },
                {
                    field : 'protrait',
                    title : '头像',
                    formatter: function(value, row, index) {
                    	if(value){
                    		return $.table.imageView(value);
                        }
                    	return ''
                	}
                },
                {
                    field : 'thirdType',
                    title : '登陆类型'
                },
                {
                    field : 'phone',
                    title : '手机'
                },
                {
                    field : 'regTime',
                    title : '注册时间'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="privilegeList(\'' + row.kkid + '\', \'' + row.appId + '\')"><i class="fa fa-edit"></i>用户特权列表</a> ');
                        if(row.appId == 'kkyuwen100' || row.appId == 'wyw' || row.appId == 'kkdictios' || row.appId == 'kkdict' || row.appId == 'dictkx' || row.appId == 'dictsw' || row.appId == 'cidianhy' || row.appId == 'kkpoem' || row.appId == 'dictkxios' || row.appId == 'dictswios' || row.appId == 'kkyuwen' ){
                           actions.push(`<a class="btn btn-info btn-xs ${editFlag}" href="javascript:void(0)" onclick="sendPrivilege('${row.no}', '${row.kkid}', '${row.appId}')"><i class="fa fa-user"></i>发放会员</a>`);
                        }
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });

        function privilegeList(kkid, appId) {
		    var url = privilegePrefix + "/" + kkid + "/" + appId;
		    //$.modal.open("用户特权列表", url);
		    $.modal.open("用户特权列表", url, "", "", function(index, layero){
               layer.close(index);
		    });
		}

        function sendPrivilege(kkno, kkid, appId){
           var url = `${sendPrivilegePrefix}/${kkno}/${kkid}/${appId}`;
           $.modal.open("添加特权", url);
        }
    </script>
</body>
</html>